package com.ruoyi.customerSample.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;

import com.ruoyi.customerSample.domain.ContractBasicInfo;
import com.ruoyi.customerSample.service.IContractBasicInfoService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 检测合同基本信息Controller
 * 
 * @author lgq
 * @date 2023-05-12
 */
@RestController
@RequestMapping("/custSam/contract")
@Api(value="检测合同",tags = "检测合同基本信息接口")
public class ContractBasicInfoController extends BaseController
{
    @Autowired
    private IContractBasicInfoService contractBasicInfoService;

    /**
     * 查询检测合同基本信息列表
     */
    @GetMapping("/list")
    @ApiOperation(value="查询检测合同基本信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    public TableDataInfo list(ContractBasicInfo contractBasicInfo)
    {
        startPage();
        List<ContractBasicInfo> list = contractBasicInfoService.selectContractBasicInfoList(contractBasicInfo);
        return getDataTable(list);
    }

    /**
     * 导出检测合同基本信息列表
     */
    @Log(title = "检测合同基本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ContractBasicInfo contractBasicInfo)
    {
        List<ContractBasicInfo> list = contractBasicInfoService.selectContractBasicInfoList(contractBasicInfo);
        ExcelUtil<ContractBasicInfo> util = new ExcelUtil<ContractBasicInfo>(ContractBasicInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取检测合同基本信息详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value="获取检测合同基本信息详细信息")
    @ApiImplicitParam(paramType="query", name = "id", value = "主键", required = true, dataType = "String")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(contractBasicInfoService.selectContractBasicInfoById(id));
    }

    /**
     * 获取检测合同基本信息详细信息
     */
    @GetMapping("getInfoByNum/{contractNum}")
    @ApiOperation(value="获取检测合同基本信息详细信息")
    @ApiImplicitParam(paramType="query", name = "contractNum", value = "合同号", required = true, dataType = "String")
    public AjaxResult getInfoByNum(@PathVariable("contractNum") String contractNum)
    {
        return AjaxResult.success(contractBasicInfoService.selectContractBasicInfoByNum(contractNum));
    }

    /**
     * 新增检测合同基本信息
     */
    @Log(title = "检测合同基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="新增检测合同基本信息")
    public AjaxResult add(@ApiParam(name="检测合同基本信息",value="传入json格式",required=true)@RequestBody ContractBasicInfo contractBasicInfo)
    {
        contractBasicInfo.setId(IdUtils.fastSimpleUUID());
        contractBasicInfo.setUploader(SecurityUtils.getUsername());
        contractBasicInfo.setUploadTime(DateUtils.getNowDate());
        return toAjax(contractBasicInfoService.insertContractBasicInfo(contractBasicInfo));
    }

    /**
     * 修改检测合同基本信息
     */
    @Log(title = "检测合同基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value="修改检测合同基本信息")
    public AjaxResult edit(@ApiParam(name="检测合同基本信息",value="传入json格式",required=true)@RequestBody ContractBasicInfo contractBasicInfo)
    {
        return toAjax(contractBasicInfoService.updateContractBasicInfo(contractBasicInfo));
    }

    /**
     * 删除检测合同基本信息wwa
     */
    @Log(title = "检测合同基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value="删除检测合同基本信息")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(contractBasicInfoService.deleteContractBasicInfoByIds(ids));
    }
}
